package com.ruan.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruan.entity.R;
import com.ruan.entity.Shoppingcart;
import com.ruan.entity.User;
import com.ruan.mapper.UserMapper;
import com.ruan.service.ShoppingcartService;
import com.ruan.mapper.ShoppingcartMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
* @author 59499
* @description 针对表【tb_shoppingcart】的数据库操作Service实现
* @createDate 2023-09-20 15:00:05
*/
@Service
public class ShoppingcartServiceImpl extends ServiceImpl<ShoppingcartMapper, Shoppingcart>
    implements ShoppingcartService{

    @Autowired
    private UserMapper userMapper;

    @Autowired
    private ShoppingcartMapper shoppingcartMapper;

    @Override
    public R<Void> addShoppingCart(Map<String, Integer> map) {
        User user = userMapper.selectById(map.get("userId"));
        Shoppingcart shoppingcart = new Shoppingcart();
        shoppingcart.setOrderId(map.get("orderId"));
        shoppingcart.setOwnName(user.getUsername());
        shoppingcart.setCount(1);
        int row = shoppingcartMapper.insert(shoppingcart);
        if (row != 1){
            return R.error("添加购物车失败");
        }
        return R.ok("添加购物车成功");
    }
}




